﻿// ***********************************************************************
// Assembly         : MVC4Portal
// Author           : LJO+01 (Laurent Jordi)
// Created          : 06-05-2013
// Last Modified By : LJO+01 (Laurent Jordi)
// Last Modified On : 06-05-2013
// ***********************************************************************
// <copyright file="_DynaContents_Base.cs" company="Copyright © Innovacall 2011">
//     Copyright (c) Copyright © Innovacall 2011. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Linq;
using System.Transactions;
using System.Web.Mvc;
using System.Web.Security;
using EmitMapper;
using InnovaApp.Layers.CommonLayer.Controllers.ViewControllers.LayoutViewControllers;
using InnovaApp.Layers.DataLayer;
using InnovaApp.Layers.DomainLayer;
using InnovaApp.Layers.ResourcesLayer.Properties;
using InnovaApp.Portals.MVC4Portal.Models.MetaModels.ContentManagement;
using InnovaApp.Portals.MVC4Portal.Models.ViewModels.LayoutViewModels.DynaContentViewModels;
using INNOVACALL.Framework.Common;
using INNOVACALL.Framework.Common.Extensions;
using INNOVACALL.Framework.Common.HTMLHelpers;
using INNOVACALL.Framework.Common.Logging;
using INNOVACALL.Framework.Common.MVCHelpers.Localization;

namespace InnovaApp.Portals.MVC4Portal.Controllers.ViewControllers.LayoutViewControllers.DynaContents
{
    /// <summary>
    /// Class _DynaContents_Base
    /// </summary>
    public abstract class _DynaContents_Base : _LayoutViewControllers_Base<DynaContent_ViewModel>
    {

        /// <summary>
        /// Dynas the content initialization.
        /// </summary>
        /// <param name="requestContext">The request context.</param>
        protected void DynaContentInitialization(System.Web.Routing.RequestContext requestContext)
        {
            List<string> lstSpecificCssCollection = new List<string>();
            List<string> lstSpecificJqueryJSCollection = new List<string>();

            base.eMethodBase = "InnovaApp.Portals.InnovaAppFrontOfficePortal.Controllers._DynaContents_Base";
            lstSpecificCssCollection.AddRange((new string[] { "Views/DynaContent.css", string.Format(@"ClientComponents/KendoUI/kendo.{0}.min.css", PortalEnvironment.KendoUITheme.ToLower()) }).ToList());
            if (this.AdminMode)
            {
                lstSpecificCssCollection.Add("Views/DynaContentAdmin.css");
            }
            base.specificCssCollection = lstSpecificCssCollection.ToArray();
            base.specificJSCollection = null;
            base.dynamicJSCollection = new string[] { "/ScriptsG/DynaContentDynamic.js" };
            lstSpecificJqueryJSCollection.AddRange(
                new string[] { 
                    "ClientComponents/Jquery.FriendlyUrl/jquery.friendurl.js",
                    "JSonModels/JSonModelsMenuEdition1.js"                
                }
            );
            if (this.AdminMode)
            {
                lstSpecificJqueryJSCollection.Add("Views/DynaContentAdmin.js");
#if DEBUG
                lstSpecificJqueryJSCollection.Add("ClientComponents/tiny_mce/tiny_mce_src.js");
#else
                lstSpecificJqueryJSCollection.Add("ClientComponents/tiny_mce/tiny_mce.js");
#endif
                lstSpecificJqueryJSCollection.Add("ClientComponents/CodeMirror/lib/codemirror.js");
                lstSpecificJqueryJSCollection.Add("ClientComponents/CodeMirror/mode/javascript/javascript.js");
                lstSpecificJqueryJSCollection.Add("ClientComponents/CodeMirror/mode/css/css.js");
                lstSpecificJqueryJSCollection.Add("ClientComponents/CodeMirror/mode/xml/xml.js");
                lstSpecificJqueryJSCollection.Add("ClientComponents/CodeMirror/lib/util/formatting.js");
                lstSpecificJqueryJSCollection.Add("ClientComponents/CodeMirror/mode/htmlmixed/htmlmixed.js");
                lstSpecificJqueryJSCollection.Add("ClientComponents/CodeMirror/mode/htmlmixed/htmlmixed.js");
                lstSpecificJqueryJSCollection.Add("ClientComponents/JQuerySimpleColorPicker/jquery.simplecolorpicker.js");
                lstSpecificJqueryJSCollection.Add("ClientComponents/gridster/jquery.gridster.js");
                lstSpecificJqueryJSCollection.Add("ClientComponents/gridster/jquery.gridster.extras.js");
                lstSpecificJqueryJSCollection.Add("ClientComponents/gridster/jquery.gridster.innovacall.extras.js");
                lstSpecificCssCollection.Add("ClientComponents/CodeMirror/lib/codemirror.css");
                lstSpecificCssCollection.Add("ClientComponents/JQuerySimpleColorPicker/jquery.simplecolorpicker.css");
                lstSpecificCssCollection.Add("ClientComponents/gridster/jquery.gridster.css");
                lstSpecificCssCollection.Add("ClientComponents/gridster/jquery.gridster.innovacall.css");
            }
            else
            {
                lstSpecificJqueryJSCollection.Add("Views/DynaContent.js");
            }
            base.specificJqueryJSCollection = lstSpecificJqueryJSCollection.ToArray();
            base.specificCssCollection = lstSpecificCssCollection.ToArray();
            base.externalCss = null;
            base.Meta = new System.Collections.Generic.Dictionary<enMeta, string>();
        }

        /// <summary>
        /// Indexes the specified friendly URL.
        /// </summary>
        /// <param name="friendlyUrl">The friendly URL.</param>
        /// <param name="language">The language.</param>
        /// <param name="controller">The controller.</param>
        /// <param name="action">The action.</param>
        /// <param name="layoutMenuId">The layout menu id.</param>
        /// <param name="structurePageId">The structure page id.</param>
        /// <param name="openingMessageResourceTag">The opening message resource tag.</param>
        /// <param name="openingMessageResourceStringFormatParameters">The opening message resource string format parameters.</param>
        /// <returns>ActionResult.</returns>
        /// <exception cref="INNOVACALL.Framework.Common.InnovacallExceptions.DataIntegrityException"></exception>
        protected ActionResult Index(
            string friendlyUrl,
            string language,
            string controller,
            string action,
            int layoutMenuId,
            int structurePageId,
            string openingMessageResourceTag,
            string[] openingMessageResourceStringFormatParameters
        )
        {
            base.LocalizeDynamicScript(language, (CurrentContact != null ? CurrentContact.FavoriteLanguage.Language : null));

            using (DataRepositories _dataContext = new DataRepositories())
            {
                string eMethod = eMethodBase + "Index[Get]";
                object eParameters = new
                {
                    friendlyUrl = friendlyUrl,
                    language = language,
                    controller = controller,
                    action = action,
                    layoutMenuId = layoutMenuId,
                    structurePageId = structurePageId,
                    openingMessageResourceTag = openingMessageResourceTag,
                    openingMessageResourceStringFormatParameters = openingMessageResourceStringFormatParameters
                };

                List<SelectListItem> indexingCategories = null;

                if (base.AdminMode)
                {
                    List<string> specificJqueryJSCollectionList = this.specificJqueryJSCollection.ToList();
                    //specificJqueryJSCollectionList.Add("ClientComponents/tiny_mce/tiny_mce.js");
                    this.specificJqueryJSCollection = specificJqueryJSCollectionList.ToArray();
                }
                string openingMessage = string.Empty;
                if (!string.IsNullOrEmpty(openingMessageResourceTag))
                {
                    openingMessage = CommonLocalization.LookupResource(typeof(Resources), openingMessageResourceTag);
                    if (openingMessageResourceStringFormatParameters != null)
                    {
                        if (openingMessageResourceStringFormatParameters.Length > 0)
                        {
                            openingMessage = string.Format(CommonLocalization.LookupResource(typeof(Resources), openingMessageResourceTag), openingMessageResourceStringFormatParameters);
                        }
                    }
                }
                base.InitView(
                    pageTitle: string.Empty,
                    openingMessage: openingMessage,
                    specificCssCollection: specificCssCollection,
                    specificJSCollection: specificJSCollection,
                    dynamicJSCollection: dynamicJSCollection,
                    specificJqueryJSCollection: specificJqueryJSCollection,
                    jsVariables: jsVariables,
                    externalJs: externalJs,
                    externalCss: externalCss,
                    metaToAdd: Meta,
                    _dataContext: _dataContext,
                    displayMenus: true,
                    language: language,
                    adminMode: base.AdminMode,
                    usesKendoUI: true,
                    jQueryUITheme: PortalEnvironment.JQueryUITheme,
                    kendoUITheme: PortalEnvironment.KendoUITheme,
                    currentUser: CurrentUser
                    );

                #region StructurePage
                Structure_Page dbStructure_Page = _dataContext.Structure_Page_Rep.Query(x => x.Id == structurePageId).FirstOrDefault();
                if (dbStructure_Page == null)
                {
                    throw new INNOVACALL.Framework.Common.InnovacallExceptions.DataIntegrityException(eMethod, eParameters, Resources.View_DyanContent_Save_Err_PageNotFound);
                }
                if (string.IsNullOrEmpty(dbStructure_Page.Description))
                {
                    ContentData._Meta.Add(enMeta.Description, string.Empty);
                }
                else
                {
                    ContentData._Meta.Add(enMeta.Description, dbStructure_Page.Description.Replace(@"""", "'"));
                }
                if (string.IsNullOrEmpty(dbStructure_Page.Keywords))
                {
                    ContentData._Meta.Add(enMeta.Keywords, string.Empty);
                }
                else
                {
                    ContentData._Meta.Add(enMeta.Keywords, dbStructure_Page.Keywords.Replace(@"""", "'"));
                }
                ContentData._PageTitle = dbStructure_Page.Title;
                ContentData.StructurePage = ObjectMapperManager.DefaultInstance.GetMapper<Structure_Page, Structure_Page_MetaModel>().Map(dbStructure_Page);
                #endregion

                ContentData.ControllerName = dbStructure_Page.LayoutMenu_Translation.LayoutMenu.Controller;

                ManagedContent dbManagedContent = _dataContext.ManagedContent_Rep.Query(x => x.FK_Structure_Page == dbStructure_Page.Id).SingleOrDefault();
                if (dbManagedContent == null)
                {
                    dbManagedContent = PrepareEmptyManagedContent(dbStructure_Page.Id, language, CurrentUser);
                    _dataContext.ManagedContent_Rep.Add(dbManagedContent);
                    _dataContext.Save();
                }
                ContentData.ManagedContent = ObjectMapperManager.DefaultInstance.GetMapper<ManagedContent, ManagedContent_MetaModel>().Map(dbManagedContent);
                ContentData.StructurePage.IndexingCategories = GetIndexingCategories(_dataContext, ContentData.StructurePage.IndexingCategory);
                ContentData.StructurePage.RevisitAfterOptions = GetRevisitAfterOptions(ContentData.StructurePage.RevisitAfter);
                ContentData.StructurePage.RobotOptions = GetRobotOptions(ContentData.StructurePage.Robots);
                ContentData.Controllers.Add(new SelectListItem() { Value = "DynaContentPublicController", Text = Resources.View_LayoutMenu_DefaultControllersPublic, Selected = true });
                ContentData.Controllers.Add(new SelectListItem() { Value = "DynaContentPrivateController", Text = Resources.View_LayoutMenu_DefaultControllersPrivate, Selected = true });
                ContentData.Controllers.AddRange(LayoutViewControllersStaticTools.GetCustomControllersList());
                //LayoutJSVariables
                if (ContentData._AdminMode)
                {
                    switch (ContentData._enCurrentSiteLayout)
                    {
                        case Layers.CommonLayer.Models.ViewModels.LayoutViewModels.enSiteLayouts.MenuLeft:
                            ContentData._JSVariables.Add(string.Format("var layoutVar_divBodyPaddingTop = {0};\n", PortalEnvironment.DynamicSettings[enDynamicSettings.MenuLeft_ContentBodyPaddingTop]));
                            ContentData._JSVariables.Add(string.Format("var layoutVar_divBodyPaddingLeft = {0};\n", PortalEnvironment.DynamicSettings[enDynamicSettings.MenuLeft_ContentBodyPaddingLeft]));
                            ContentData._JSVariables.Add(string.Format("var layoutVar_divBodyPaddingRight = {0};\n", PortalEnvironment.DynamicSettings[enDynamicSettings.MenuLeft_ContentBodyPaddingRight]));
                            ContentData._JSVariables.Add(string.Format("var layoutVar_divBodyPaddingBottom = {0};\n", PortalEnvironment.DynamicSettings[enDynamicSettings.MenuLeft_ContentBodyPaddingBottom]));
                            break;
                        case Layers.CommonLayer.Models.ViewModels.LayoutViewModels.enSiteLayouts.MenuTop:
                            ContentData._JSVariables.Add(string.Format("var layoutVar_divBodyPaddingTop = {0};\n", PortalEnvironment.DynamicSettings[enDynamicSettings.MenuTop_ContentBodyPaddingTop]));
                            ContentData._JSVariables.Add(string.Format("var layoutVar_divBodyPaddingLeft = {0};\n", PortalEnvironment.DynamicSettings[enDynamicSettings.MenuTop_ContentBodyPaddingLeft]));
                            ContentData._JSVariables.Add(string.Format("var layoutVar_divBodyPaddingRight = {0};\n", PortalEnvironment.DynamicSettings[enDynamicSettings.MenuTop_ContentBodyPaddingRight]));
                            ContentData._JSVariables.Add(string.Format("var layoutVar_divBodyPaddingBottom = {0};\n", PortalEnvironment.DynamicSettings[enDynamicSettings.MenuTop_ContentBodyPaddingBottom]));
                            break;
                    }
                }
            }
            Logger.Info(enLog.Business, string.Format(@"IP:{0} User[{1}] with [{2}] agent access page [{3}] AdminMode=[{4}]", Request.UserHostAddress, (String.IsNullOrEmpty(ContentData._UserLogin) ? "#Anonymous#" : ContentData._UserLogin), Request.UserAgent, friendlyUrl, AdminMode));
            return View(ContentData);

        }

        /// <summary>
        /// Saves the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="model">The model.</param>
        /// <returns>JsonResult.</returns>
        /// <exception cref="INNOVACALL.Framework.Common.InnovacallExceptions.DataIntegrityException"></exception>
        protected JsonResult Save(int id, DynaContent_ViewModel model)
        {
            string eMethod = eMethodBase + "Save[POST]";
            object eParameters = new { model = model };
            JsonResult toReturn = new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet };
            using (DataRepositories _dataContext = new DataRepositories())
            {
                Guid LastModifierId = (Guid)(Membership.GetUser().ProviderUserKey);
                using (TransactionScope TS = new TransactionScope())
                {
                    try
                    {
                        LayoutMenu dbLayoutMenu;
                        LayoutMenu_Translation dbLayoutMenu_Translation;
                        Structure_Page dbStructure_Page;

                        dbLayoutMenu_Translation = _dataContext.LayoutMenu_Translation_Rep.Query(x => x.Id == model.StructurePage.FK_LayoutMenu_Translation).FirstOrDefault();
                        if (dbLayoutMenu_Translation == null)
                        {
                            throw new INNOVACALL.Framework.Common.InnovacallExceptions.DataIntegrityException(eMethod, eParameters, Resources.View_DyanContent_Save_Err_LayoutMenu_TranslationNull);
                        }
                        dbLayoutMenu = dbLayoutMenu_Translation.LayoutMenu;
                        dbStructure_Page = dbLayoutMenu_Translation.Structure_Page.Where(x => x.Id == model.StructurePage.Id).FirstOrDefault();
                        if (dbStructure_Page == null)
                        {
                            dbStructure_Page = new Structure_Page();
                            dbStructure_Page.DateVersion = DateTime.Now;
                            dbStructure_Page.Description = model.StructurePage.Description;
                            dbStructure_Page.Keywords = model.StructurePage.Keywords;
                            dbStructure_Page.FK_LayoutMenu_Translation = dbLayoutMenu.Id;
                            dbStructure_Page.IndexingCategory = model.StructurePage.IndexingCategory;
                            dbStructure_Page.IsActive = true; //ToDo Mange Page Activation
                            dbStructure_Page.LastBuildDate = DateTime.Now;
                            dbStructure_Page.DirectURL = string.Empty; //Reserved for InnovaCMS
                            dbStructure_Page.PublicationDate = DateTime.Now; //ToDo Mange delayed publication
                            dbStructure_Page.ReadyToPublish = true; //ToDo Mange delayed publication
                            dbStructure_Page.RevisitAfter = model.StructurePage.RevisitAfter;
                            dbStructure_Page.Robots = model.StructurePage.Robots;
                            dbStructure_Page.Title = model.StructurePage.Title;
                            _dataContext.Structure_Page_Rep.Add(dbStructure_Page);
                        }
                        else
                        {
                            dbStructure_Page.DateVersion = DateTime.Now;
                            dbStructure_Page.Title = model.StructurePage.Title;
                            dbStructure_Page.Description = model.StructurePage.Description;
                            dbStructure_Page.Keywords = model.StructurePage.Keywords;
                            dbStructure_Page.IndexingCategory = model.StructurePage.IndexingCategory;
                            dbStructure_Page.IsActive = true; //ToDo Mange Page Activation
                            dbStructure_Page.LastBuildDate = DateTime.Now;
                            dbStructure_Page.PublicationDate = DateTime.Now; //ToDo Mange delayed publication
                            dbStructure_Page.ReadyToPublish = true; //ToDo Mange delayed publication
                            dbStructure_Page.RevisitAfter = model.StructurePage.RevisitAfter;
                            dbStructure_Page.Robots = model.StructurePage.Robots;
                            _dataContext.Structure_Page_Rep.AddUpdate(dbStructure_Page);
                        }
                        _dataContext.Save();
                        ManagedContent dbManagedContent = _dataContext.ManagedContent_Rep.GetById(model.ManagedContent.Id);
                        if (dbManagedContent == null)
                        {
                            dbManagedContent = PrepareEmptyManagedContent(dbStructure_Page.Id, GetLanguageDescriptionWithFriendlyURL(Request.UrlReferrer.AbsolutePath), CurrentUser);
                            _dataContext.ManagedContent_Rep.Add(dbManagedContent);
                        }
                        else
                        {
                            dbManagedContent.ContentHTML = model.ManagedContent.ContentHTML;
                            dbManagedContent.ContentText = model.ManagedContent.ContentHTML.ExtractTextFromHTML();
                            dbManagedContent.CSSExtension = model.ManagedContent.CSSExtension;
                            dbManagedContent.JSExtension = model.ManagedContent.JSExtension;
                            dbManagedContent.LastUpdate = DateTime.Now;
                            if (dbManagedContent.FK_AppUser_LastModificator == null)
                            {
                                dbManagedContent.FK_AppUser_Creator = LastModifierId;
                            }
                            dbManagedContent.FK_AppUser_LastModificator = LastModifierId;
                            if (string.IsNullOrEmpty(model.ManagedContent.ResumeHTML))
                            {
                                dbManagedContent.ResumeHTML = null;
                                dbManagedContent.ResumeText = null;
                            }
                            else
                            {
                                dbManagedContent.ResumeHTML = model.ManagedContent.ResumeHTML;
                                dbManagedContent.ResumeText = model.ManagedContent.ResumeHTML.ExtractTextFromHTML();
                            }
                            _dataContext.ManagedContent_Rep.AddUpdate(dbManagedContent);
                        }
                        _dataContext.Save();
                        toReturn.Data = new { success = true, message = Resources.View_DyanContent_PageSaved, scriptToExecute = "$.fn.jqDialogAlert('My Pretty CMS',a.message,'');" };
                        TS.Complete();
                    }
                    catch (Exception ex)
                    {
                        TS.Dispose();
                        INNOVACALL.Framework.Common.InnovacallExceptions.CommonException iex = new INNOVACALL.Framework.Common.InnovacallExceptions.CommonException(eMethod, eParameters, ex.Message);
                        iex.LogIt();
                        toReturn.Data = new { success = false, message = ex.Message, scriptToExecute = "$.fn.jqDialogAlert('My Pretty CMS',a.message,'');" };
                        return toReturn;
                    }
                }
            }
            return toReturn;
        }
        /// <summary>
        /// Gets the indexing categories.
        /// </summary>
        /// <param name="_dataContext">The _data context.</param>
        /// <param name="toSelect">To select.</param>
        /// <returns>List{SelectListItem}.</returns>
        private List<SelectListItem> GetIndexingCategories(DataRepositories _dataContext, string toSelect)
        {
            List<SelectListItem> toReturn = new List<SelectListItem>();
            toReturn = _dataContext.IndexingCategory_Rep.GetAll().Select(x => new SelectListItem() { Value = x.Name, Text = x.Name, Selected = (x.Name == toSelect) }).OrderBy(x => x.Text).ToList();
            toReturn.Insert(0, new SelectListItem() { Value = "", Text = "", Selected = (toSelect == "") });
            return toReturn;
        }

        /// <summary>
        /// Gets the revisit after options.
        /// </summary>
        /// <param name="toSelect">To select.</param>
        /// <returns>List{SelectListItem}.</returns>
        private List<SelectListItem> GetRevisitAfterOptions(string toSelect)
        {
            List<SelectListItem> toReturn = new List<SelectListItem>();
            foreach (var item in EnumTools.EnumerateEnum<enMetaRevisitAfter>())
            {
                string value = item.ToString();
                string text = EnumTools.EnumTypeTo<enMetaRevisitAfter>(value).HTMLProperties().HTMLValue;
                toReturn.Add(new SelectListItem() { Value = text, Text = text, Selected = text == toSelect });
            }
            toReturn.Insert(0, new SelectListItem() { Value = "-1", Text = "", Selected = (toSelect == "") });
            return toReturn;
        }

        /// <summary>
        /// Gets the robot options.
        /// </summary>
        /// <param name="toSelect">To select.</param>
        /// <returns>List{SelectListItem}.</returns>
        private List<SelectListItem> GetRobotOptions(string toSelect)
        {
            List<SelectListItem> toReturn = new List<SelectListItem>();
            foreach (Enum item in EnumTools.EnumerateEnum<enMetaRobotsOptions>())
            {
                string value = item.ToString();
                string text = EnumTools.EnumTypeTo<enMetaRobotsOptions>(value).HTMLProperties().HTMLValue;
                toReturn.Add(new SelectListItem() { Value = text, Text = text, Selected = (text == toSelect) });
            }
            toReturn.Insert(0, new SelectListItem() { Value = "", Text = "", Selected = (toSelect == "") });
            return toReturn;
        }

        /// <summary>
        /// Prepares the empty structure page.
        /// </summary>
        /// <param name="menuTranslationId">The menu translation id.</param>
        /// <param name="pageNameUrlFormatted">The page name URL formatted.</param>
        /// <param name="friendlyUrl">The friendly URL.</param>
        /// <param name="language">The language.</param>
        /// <param name="title">The title.</param>
        /// <returns>Structure_Page.</returns>
        internal static Structure_Page PrepareEmptyStructurePage(int menuTranslationId, string pageNameUrlFormatted, string friendlyUrl, string language, string title)
        {
            Structure_Page toReturn = new Structure_Page();
            toReturn.Id = -1;
            toReturn.Title = title;
            toReturn.DateVersion = DateTime.Now;
            toReturn.Description = string.Empty;
            //Warning Les cultures doivent être définies en minuscules
            //ToDo Refaire le bloc de selection de la langue au propre
            toReturn.FK_LayoutMenu_Translation = menuTranslationId;
            toReturn.IndexingCategory = null;
            toReturn.IsActive = true;
            toReturn.Keywords = "Innovacall, Microsoft, ASP.net MVC, C#, MyPrettyCMS";
            toReturn.LastBuildDate = DateTime.Now;
            toReturn.DirectURL = friendlyUrl;
            toReturn.PageNameURLFormatted = pageNameUrlFormatted;
            toReturn.PublicationDate = DateTime.Now;
            toReturn.ReadyToPublish = true; //Reserved for InnovaCMS
            toReturn.RevisitAfter = StringEnum.GetStringValue(enMetaRevisitAfter.FiveteenDays);
            toReturn.Robots = StringEnum.GetStringValue(enMetaRobotsOptions.Index_Follow);
            toReturn.SortIndex = 1;
            return toReturn;
        }
        /// <summary>
        /// Prepares the empty content of the managed.
        /// </summary>
        /// <param name="structurePageId">The structure page id.</param>
        /// <param name="language">The language.</param>
        /// <returns>ManagedContent.</returns>
        internal static ManagedContent PrepareEmptyManagedContent(int structurePageId, string language, MembershipUser currentUser)
        {
            ManagedContent toReturn = new ManagedContent();
            toReturn.Id = -1;
            toReturn.Creation = DateTime.Now;
            toReturn.LastUpdate = DateTime.Now;
            toReturn.FK_Structure_Page = structurePageId;
            toReturn.FK_AppUser_Creator = (Guid)(currentUser).ProviderUserKey;
            toReturn.FK_AppUser_LastModificator = null;
            toReturn.ResumeHTML = string.Empty;
            toReturn.ResumeText = string.Empty;
            toReturn.CSSExtension = string.Empty;
            toReturn.JSExtension = string.Empty;
            string underConstr = "Under construction";
            CultureInfo ci = CultureInfo.CreateSpecificCulture(language);
            underConstr = InnovaApp.Layers.ResourcesLayer.Properties.Resources.ResourceManager.GetString("View_All_UnderConstruction", ci);
            toReturn.ContentHTML = string.Format(@"
<div class=""gridster  ready"">
    <ul style=""height: 800px; position: relative;"" class=""gridsterUl  gs-resize-disabled"">
        <li style="""" id=""MyPrettyCMSContentSlot-1"" class=""gridsterLi MyPrettyCMSSlot gs-w"" data-row=""1"" data-col=""1"" data-sizex=""27"" data-sizey=""20""><div style=""display: none;"" class=""ui-icon ui-icon-trash layoutSlotDrop""></div>
            <div style=""width: 1060px; height: 780px;"" id=""MyPrettyCMSContentSlot-1LayoutSlot"" class=""mceEditable layoutSlot""><p>{0}</p></div>
        <span class=""gs-resize-handle gs-resize-handle-x""></span><span class=""gs-resize-handle gs-resize-handle-y""></span><span class=""gs-resize-handle gs-resize-handle-both""></span></li>
    </ul>
</div>

", underConstr);
            toReturn.ContentText = underConstr;
            return toReturn;
        }
    }
}